package com.wustl.android.hood;

import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;

import com.google.android.maps.MapActivity;

public class ItemMain extends MapActivity {
	
	protected DbLocations mDbHelper;
	
	public void onCreate(Bundle icicle) {
		super.onCreate(icicle);
		setContentView(R.layout.item_main);
		
		Intent i = getIntent();
		
		mDbHelper = new DbLocations(this);
		mDbHelper.open();
		
		Long itemLocationId = Long.valueOf(i.getData().toString());
		Cursor row = mDbHelper.fetchLocation(itemLocationId);
		
		ImageView typeIcon = (ImageView)findViewById(R.id.item_type_icon);

		final int type = row.getInt( row.getColumnIndex(DbLocations.KEY_TYPE) );
		typeIcon.setImageResource( HoodMain.getTypeIconResource(type) );
		
		TextView tvName = (TextView)findViewById(R.id.item_name);
		tvName.setText( row.getString( row.getColumnIndex( DbLocations.KEY_TITLE ) ));

		TextView tvLatitude = (TextView)findViewById(R.id.item_latitude);
		final double latitude = row.getDouble(row.getColumnIndex( DbLocations.KEY_LATITUDE ));
		tvLatitude.setText( "Latitude: " + latitude );
		
		TextView tvLongitude = (TextView)findViewById(R.id.item_longitude);
		final double longitude = row.getDouble( row.getColumnIndex( DbLocations.KEY_LONGITUDE ) );
		tvLongitude.setText( "Longitude: " + longitude );
		
		HoodItemMainActions actions = (HoodItemMainActions)findViewById(R.id.MainItem_Actions);
		actions.itemLocationId = itemLocationId;
		
		ItemMainMapBar mapBar =(ItemMainMapBar)findViewById(R.id.ItemMainMapBar);
		mapBar.setCurrentLocation( row );
	}
}
